package ui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import td.Dwarf;
import td.Elf;

/*
 * View class to represent Elves on the map.
 * */
public class ElfView extends EnemyView {

	public ElfView(Elf elf) {
		super(elf);
		// this.setLayout(new GridBagLayout());
		/*Sets the displayable image.*/
		image = Toolkit.getDefaultToolkit().getImage("Images/elf.png");
		GridBagConstraints gridc = new GridBagConstraints();
		gridc.gridx = 0;
		gridc.gridy = 0;
		/*Sets up the hp display.*/
		gridc.anchor = GridBagConstraints.FIRST_LINE_END;
		hp = new JLabel("" + ((Elf) fieldElement).getHp());
		hp.setForeground(Color.cyan);
		add(hp, gridc);
		/*Puts up picture of the enemy*/
		gridc.anchor = GridBagConstraints.LAST_LINE_START;
		JLabel picLabel = new JLabel(new ImageIcon(image));
		add(picLabel, gridc);
		update();
	}

	/*
	 * Function to update the enemy's current hp display
	 * and put up status effect icons in the corner of
	 * the displayed picture, so the player knows
	 * if the unit is either slowed or set on fire.
	 * */
	@Override
	public void update() {
		hp.setText("" + ((Elf) fieldElement).getHp());
		if (((Elf) fieldElement).onFire) {
			fire.setVisible(true);
		} else {
			fire.setVisible(false);
		}
		if (((Elf) fieldElement).slowed) {
			slow.setVisible(true);
		} else {
			slow.setVisible(false);
		}

		// crit.setVisible(true);

	}

	public void paintComponent(Graphics g) {
		super.paintComponents(g);
		Graphics2D g2D = (Graphics2D) g;
		g2D.drawImage(image, 0, 0, this);
	}
}
